/*     */ package com.zimbra.cs.pop3;
/*     */ 
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.security.sasl.Authenticator;
/*     */ import com.zimbra.cs.server.NioConnection;
/*     */ import com.zimbra.cs.server.NioHandler;
/*     */ import com.zimbra.cs.server.NioOutputStream;
/*     */ import java.io.IOException;
/*     */ import java.io.OutputStream;
/*     */ import java.net.InetSocketAddress;
/*     */ import javax.net.ssl.SSLException;
/*     */ import org.apache.mina.filter.codec.RecoverableProtocolDecoderException;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ final class NioPop3Handler
/*     */   extends Pop3Handler
/*     */   implements NioHandler
/*     */ {
/*     */   private final NioConnection connection;
/*     */   
/*     */   NioPop3Handler(NioPop3Server server, NioConnection conn)
/*     */   {
/*  34 */     super(server.getConfig());
/*  35 */     this.connection = conn;
/*  36 */     this.output = conn.getOutputStream();
/*     */   }
/*     */   
/*     */   public void connectionOpened() throws IOException
/*     */   {
/*  41 */     if (!startConnection(this.connection.getRemoteAddress().getAddress())) {
/*  42 */       this.connection.close();
/*     */     }
/*     */   }
/*     */   
/*     */   public void connectionClosed() throws IOException
/*     */   {
/*  48 */     this.connection.close();
/*     */   }
/*     */   
/*     */   public void connectionIdle()
/*     */   {
/*  53 */     ZimbraLog.pop.debug("idle connection");
/*  54 */     dropConnection();
/*     */   }
/*     */   
/*     */   public void messageReceived(Object msg) throws IOException
/*     */   {
/*  59 */     if (!processCommand((String)msg)) {
/*  60 */       dropConnection();
/*     */     }
/*     */   }
/*     */   
/*     */   public void exceptionCaught(Throwable e) throws IOException
/*     */   {
/*  66 */     if ((e instanceof SSLException)) {
/*  67 */       ZimbraLog.pop.error("Error detected by SSL subsystem, dropping connection:" + e);
/*  68 */       dropConnection();
/*  69 */     } else if ((e instanceof RecoverableProtocolDecoderException)) {
/*  70 */       RecoverableProtocolDecoderException re = (RecoverableProtocolDecoderException)e;
/*  71 */       int hexdumpIdx = re.getMessage() != null ? re.getMessage().indexOf("(Hexdump:") : -1;
/*  72 */       if (hexdumpIdx >= 0) {
/*  73 */         sendERR(e.getMessage().substring(0, hexdumpIdx));
/*     */       } else {
/*  75 */         sendERR(e.getMessage());
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public void dropConnection()
/*     */   {
/*  82 */     if (!this.connection.isOpen()) {
/*  83 */       return;
/*     */     }
/*     */     try {
/*  86 */       this.output.close();
/*     */     }
/*     */     catch (IOException never) {}
/*  89 */     this.connection.close();
/*     */   }
/*     */   
/*     */   protected void startTLS() throws IOException
/*     */   {
/*  94 */     this.connection.startTls();
/*  95 */     sendOK("Begin TLS negotiation");
/*     */   }
/*     */   
/*     */   protected void completeAuthentication() throws IOException
/*     */   {
/* 100 */     if (this.authenticator.isEncryptionEnabled()) {
/* 101 */       this.connection.startSasl(this.authenticator.getSaslServer());
/*     */     }
/* 103 */     this.authenticator.sendSuccess();
/*     */   }
/*     */   
/*     */   InetSocketAddress getLocalAddress()
/*     */   {
/* 108 */     return this.connection.getLocalAddress();
/*     */   }
/*     */   
/*     */   void sendLine(String line, boolean flush) throws IOException
/*     */   {
/* 113 */     NioOutputStream nioutput = (NioOutputStream)this.output;
/* 114 */     nioutput.write(line);
/* 115 */     nioutput.write(LINE_SEPARATOR);
/* 116 */     if (flush) {
/* 117 */       nioutput.flush();
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/pop3/NioPop3Handler.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */